package com.chao.wind3j.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

    public static String getFormatDate(Date date){
        return getFormateDate(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String getFormatDate(Date date, DateFormat dateFormat) {
        return getFormateDate(date, dateFormat.getFormat());
    }

    public static String getFormateDate(Date date, String dateFormat) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
        return simpleDateFormat.format(date);
    }

    public static Date getDateFromFormat(String date, DateFormat dateFormat) {
        return getDateFromFormat(date, dateFormat.getFormat());
    }

    public static Date getDateFromFormat(String date, String dateFormat) {
        if (date == null) {
            return null;
        }
        Date rDate = null;
        try {
            rDate = (new SimpleDateFormat(dateFormat)).parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return rDate;
    }
}
